import axios from 'axios'

const http = axios.create({
    baseURL: '/api',
    timeout: 1000,
    // headers: { 'X-Custom-Header': 'foobar' }
})
let API = axios.create({
    baseURL: '/api',
    timeout: 1000,
})

http.interceptors.request.use(function (config) {
    // Do something before request is sent
    config.headers['X-Token'] = sessionStorage.getItem('token')
    return config;
}, function (error) {
    // Do something with request error
    return Promise.reject(error);
})

// API.interceptors.response.use(function (response) {
//     // Any status code that lie within the range of 2xx cause this function to trigger
//     // Do something with response data 609o
//     if (response.code === 200) {// http状态码
//         if (response, data.status === 'sucess') {
//             return respons
//         } else {
//             alert(response.data.status, response.data.message)//·错误处理
//             return new Error('请求失败')
//         }
//     }
//     return response;
// }, function (error) {
//     // Any status codes that falls outside the range of 2xx cause this function to trigger
//     // Do something with response error
//     return Promise.reject(error);

// })
export { API, http };
